from django.db import models
from staff.models import Client, Vendor
from inventory.models import *

class Sale(models.Model):
    made = models.DateTimeField(null=False, blank=False)
    client = models.ForeignKey(Client)
    vendor = models.ForeignKey(Vendor)
    payment_method = models.IntegerField(null=False, blank=False)
    bill_number = models.IntegerField(null=False, blank=False)
    discount = models.FloatField(null=False, blank=False)
    discount_currency = models.ForeignKey(Currency)
    payed = models.BooleanField(null=False, blank=False)
    def __unicode__(self):
        return u'%s' % (self.made)
    
class ArticleSold(models.Model):
    sale = models.ForeignKey(Sale)
    item = models.ForeignKey(Item)
    
class VinylSold(models.Model):
    sale = models.ForeignKey(Sale)
    vinyl = models.ForeignKey(Vinyl)
    quantity = models.FloatField(null=False, blank=False)

class WheelSold(models.Model):
    sale = models.ForeignKey(Sale)
    wheel = models.ForeignKey(Wheel)
    trade_mark = models.CharField(max_length=30, null=False, blank=True)
    codigo = models.CharField(max_length=20, null=False, blank=False)
    price = models.FloatField(null=False, blank=False)
    currency = models.ForeignKey(Currency)
    
class Payment(models.Model):
    date = models.DateTimeField(null=False, blank=False)
    client = models.ForeignKey(Client)
    quantity = models.FloatField(null=False, blank=False)
    currency = models.ForeignKey(Currency)
    taken = models.BooleanField(null=False, blank=False, default=False)
    def __unicode__(self):
        return u'Pago por %s %s' % (self.quantity, self.currency.symbol)
